#include <stdlib.h>
#include <time.h>
#include <stdio.h>

#define ARRAY_SIZE 10

void insertion_sort(int arr[],int len){
    if(len<1){
        printf("err!\n");
    }else if(len==1){
    }else{
        int i=0;
        int j=0;
        int temp = 0;
        for(i=1;i<len;i++){
            temp = arr[i];
            j=i-1;
            while(j>=0&&arr[j]>temp){
                    arr[j+1] = arr[j];
                j--;
            }
            arr[j+1]=temp;
        }
    }


}

int main(){
    int i = 0;
    int arr[ARRAY_SIZE];
    srand((unsigned)time(NULL));
    for(i=0;i<ARRAY_SIZE;i++){
        arr[i] = rand()%1000;
    }

    printf("sort array  [");
    for(i=0;i<ARRAY_SIZE;i++){
        printf("%d",arr[i]);
        if(i<ARRAY_SIZE-1){
            printf(",");
        }
    }
    printf("] \n");
    insertion_sort(arr,ARRAY_SIZE);
    printf("sort result [");
    for(i=0;i<ARRAY_SIZE;i++){
        printf("%d",arr[i]);
        if(i<ARRAY_SIZE-1){
            printf(",");
        }
    }
    printf("] \n");

    return 0;
}

